s = "abcevaefegsgdghfdefavbdr"
d = dict() # {} 这个也是字典
d_sort = []
# 统计
for c in s:
    d[c] = d.setdefault(c, 0) + 1

print(d)
print('~' * 100)
# 排序
for c in d:
    if not d_sort or d[d_sort[-1]] <= d[c]:
        d_sort.append(c)
        continue
    for i in range(len(d_sort)):
        if d[c] < d[d_sort[i]]:
            d_sort[i], c = c, d_sort[i]
    d_sort.append(c)
# print(d_sort)
# top
length = len(d_sort)
for i in range(1,length+1):
    print((d_sort[-i], d[d_sort[-i]]))
#top 3 char
print('~' * 100)
from collections import defaultdict,OrderedDict
#top_dict = defaultdict(list)
top_dict = OrderedDict()
for i in range(length-1,-1,-1):
    if d[d_sort[i]] not in top_dict.keys():
        top_dict[d[d_sort[i]]] = []
    top_dict[d[d_sort[i]]].append(d_sort[i])
#print(top_dict)
#show top 3
count = 3
for item in top_dict.items():
    print(item)
    count -= 1
    if not count:
        break

# good~